<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ page import="com.biz.utils.ConfigUtil" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
    String resoursUrl = ConfigUtil.get("RESOURCES_URL");
%>

<!doctype html>
<html class="no-js"  style=" background: -webkit-gradient(linear, 0% 0%, 0% 100%,from(#FFFFFF), to(#FFFFFF)); padding-bottom:50px;">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>门店列表</title>
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <meta name="format-detection" content="telephone=no" />
    <link rel="stylesheet" href="<%=resoursUrl%>resources/assets/css/dxy.css" />
    <link rel="stylesheet" href="<%=resoursUrl%>resources/assets/css/NnOrange.css" />
    <jsp:include page="/jsp/inc_head.jsp"></jsp:include>
    <style>
        img.shanghupic{
            height:65px;
            width:65px;
        }
        .infogg{
            padding:0;
            line-height:16px;
        }
        .siglie{
            border-bottom:1px solid #eee;
        }
    </style>
</head>

<body style="" id="bodyHtml">
</div>
<script>
    var resBody1 = eval('${resBody}');
    if(resBody1.length > 0)
    {
        getLocation();
    }
    var EARTH_RADIUS = 6378137.0;    //单位M
    var PI = Math.PI;
    var userLat = 0;
    var userLng = 0;
    loadHtml();
    function getRad(d){
        return d*PI/180.0;
    }
    //获取用户经纬度
    function getLocation(){
        if(navigator.geolocation)
        {
            navigator.geolocation.getCurrentPosition( // 该函数有如下三个参数
                    function(pos){ // 如果成果则执行该回调函数
                        userLat = pos.coords.latitude;
                        userLng = pos.coords.longitude;
//                        alert(
//                                '  经度：' + pos.coords.latitude +
//                                '  纬度：' + pos.coords.longitude +
//                                '  高度：' + pos.coords.altitude +
//                                '  精确度(经纬)：' + pos.coords.accuracy +
//                                '  精确度(高度)：' + pos.coords.altitudeAccuracy +
//                                '  速度：' + pos.coords.speed
//                        );
                    }, function(err){ // 如果失败则执行该回调函数
                        var aa = err.code;
                        if(aa==1 || aa ==2 ){
                            alert("请设置允许获取定位");
                        }
                    }, { // 附带参数
                        enableHighAccuracy: false, // 提高精度(耗费资源)
                        timeout: 3000, // 超过timeout则调用失败的回调函数
                        maximumAge: 1000 // 获取到的地理信息的有效期，超过有效期则重新获取一次位置信息
                    }
            );
        }
    }

    function loadHtml()
    {
        var resBody = eval('${resBody}');
        var html = '';
        if(resBody.length > 0)
        {
            for(var i=0; i < resBody.length; i++)
            {
                var obj = resBody[i];
                html+='<div class="am-u-sm-12 am-pad-none siglie">'+
                        '                <div class="am-u-sm-12 orderinfo">'+
                        '                    <div class="am-u-sm-3 am-pad-none">'+
                        '                        <img src="'+obj.logo_url+'" class="shanghupic" />'+
                        '                    </div>'+
                        '                    <div class="am-u-sm-9 am-pad-none" onclick="toMapAddres(\''+obj.longitude+'\',\''+obj.latitude+'\',\''+obj.name+'\');">'+
                        '                        <div class="am-u-sm-12 am-pad-none infoname">'+obj.name+'</div>'+
                        '                        <div class="am-u-sm-12 infogg">电话：'+obj.telephone+'</div>'+
                        '                        <div class="am-u-sm-12 infogg">地址：'+obj.address+'</div>'+
                        '                        <div class="am-u-sm-12 infogg">导航'+
                        '<span class="am-icon-location-arrow"></span></div>'+
                        '                    </div>'+
                        '                </div>';
            }
        }else{
            html+='<div style="text-align: center;">暂无门店</div>';
        }

        $("#bodyHtml").html(html);
    }
    function getFlatternDistance(lat1,lng1){
        var lat2 = userLat;
        var lng2 = userLng;
        var f = getRad((lat1 + lat2)/2);
        var g = getRad((lat1 - lat2)/2);
        var l = getRad((lng1 - lng2)/2);

        var sg = Math.sin(g);
        var sl = Math.sin(l);
        var sf = Math.sin(f);

        var s,c,w,r,d,h1,h2;
        var a = EARTH_RADIUS;
        var fl = 1/298.257;

        sg = sg*sg;
        sl = sl*sl;
        sf = sf*sf;

        s = sg*(1-sl) + (1-sf)*sl;
        c = (1-sg)*(1-sl) + sf*sl;

        w = Math.atan(Math.sqrt(s/c));
        r = Math.sqrt(s*c)/w;
        d = 2*w*a;
        h1 = (3*r -1)/2/c;
        h2 = (3*r +1)/2/s;
        var dsss = d*(1 + fl*(h1*sf*(1-sg) - h2*(1-sf)*sg));
        var kk = 0;
        if(dsss > 1000){
            kk = (dsss/1000).toFixed(2)+'km';
        }else{
            kk = dsss.toFixed(2) +'m';
        }
        if(lat2 == 0)
        {
            return '无法获取位置';
        }
        return kk;
    }


    function toMapAddres(lng, lat, name)
    {
        window.location.href = "http://m.amap.com/?q="+lat+","+lng+"&name="+name;
    }

</script>
</body>
</html>
